<!-- 外部登录 -->
<template>
    <div class="single-login">
        <i class="el-icon-loading"></i>
    </div>
</template>

<script>
import request from '@/js/util/url.js';
import PATH from '@/js/util/path.js';
import config from '@/js/util/config.js';
import message from '@/js/util/message.js';
import user from '@/js/util/user.js';

export default {
    created() {
        this.login();
    },
    methods: {
        login() {
            if (this.$route.query && this.$route.query.a) {
                let result = request.getUserToken({ token: this.$route.query.a, systemid: config.getSystemID() });
                if (result.state.code === 10000) {
                    let token = result.body.message[config.getSystemID()].token;
                    user.setToken(token);
                    message.message('登录成功！');
                    let data = request.getUploadToken({
                        token: token
                    });
                    user.setUploadToken(data.body.message);
                    this.$router.push(PATH.SCENE);
                } else {
                    message.message(result.body.message, 'warning');
                    setTimeout(() => {
                        window.close();
                    }, 3000);
                }
            } else {
                message.message('访问异常，页面即将关闭...', 'error');
                setTimeout(() => {
                    window.close();
                }, 3000);
            }
        }
    }
};
</script>
<style lang='scss' scoped>
.single-login {
    height: 100vh;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
}
</style>
